import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  Patch,
  Post,
  Req,
} from '@nestjs/common';
import { FilmListService } from './film-list.service';
import { Request } from 'express';
import { CreateFilmListDto } from './dto/create-film-list.dto';
import { UpdateFilmListDto } from './dto/update-film-list.dto';
import { UpdateGrouptofilmDto } from './dto/update-grouptofilm.dto';

@Controller('film-list')
export class FilmListController {
  constructor(private readonly filmListService: FilmListService) {}

  @Post('createFilm')
  createFilm(
    @Body() createFilmListDto: CreateFilmListDto,
    @Req() request: Request,
  ) {
    const user = request.user;
    createFilmListDto.creator = (user as any).email;
    return this.filmListService.createFilm(createFilmListDto);
  }

  @Get('getAllFilms')
  getAllFilms() {
    return this.filmListService.getAllFilms();
  }

  @Get('getFilmItemById/:id')
  getFilmItemById(@Param('id') id: string) {
    return this.filmListService.getFilmItemById(id);
  }

  @Get('checkFilmById/:id')
  checkFilmById(@Param('id') id: string) {
    return this.filmListService.checkFilmById(id);
  }

  @Get('getAllFilmItemByUser')
  getAllFilmItemByUser(@Req() request: Request) {
    const user = request.user;
    const email = (user as any).email;
    return this.filmListService.getAllFilmItemByUser(email);
  }

  @Patch('updateFilmById/:id')
  updateFilmById(
    @Param('id') id: string,
    @Body() updateFilmListDto: UpdateFilmListDto,
  ) {
    return this.filmListService.updateFilmById(id, updateFilmListDto);
  }

  @Delete('removeFilmById/:id')
  removeFilmById(@Param('id') id: string) {
    return this.filmListService.removeFilmById(id);
  }

  @Get('isFilmItemExist/:filmId')
  isFilmItemExist(@Param('filmId') filmId: string) {
    return this.filmListService.isFilmItemExist(filmId);
  }

  @Get('getAllPubilcFilmItem')
  getAllPubilcFilmItem() {
    return this.filmListService.getAllPubilcFilmItem();
  }

  // 创建 小组和视频之间的关系
  @Post('createFilmItemToGroup/:groupuuid')
  createFilmItemToGroup(
    @Body() createFilmListDto: CreateFilmListDto,
    @Req() request: Request,
    @Param('groupuuid') groupuuid: string,
  ) {
    createFilmListDto.creator = (request.user as any).email;
    return this.filmListService.createFilmItemToGroup(
      createFilmListDto,
      groupuuid,
    );
  }

  @Get('getGroupToFilmItem/:filmId')
  getGroupToFilmItem(@Param('filmId') filmId: string) {
    return this.filmListService.getGroupToFilmItem(filmId);
  }

  @Post('updateFilmItemToGroup/:filmId')
  updateFilmItemToGroup(
    @Param('filmId') filmId: string,
    @Body() updateGrouptofilmDto: UpdateGrouptofilmDto,
  ) {
    return this.filmListService.updateFilmItemToGroup(
      filmId,
      updateGrouptofilmDto,
    );
  }

  @Get('getFilmItemByGroupuuid/:groupuuid')
  getFilmItemByGroupuuid(@Param('groupuuid') groupuuid: string) {
    return this.filmListService.getFilmItemByGroupuuid(groupuuid);
  }

  @Delete('deleteFilmItemFromGroup/:filmToGroupId')
  deleteFilmItemFromGroup(@Param('filmToGroupId') filmToGroupId: string) {
    return this.filmListService.deleteFilmItemFromGroup(filmToGroupId);
  }
}
